<!-- blueimp Gallery styles -->
<link rel="stylesheet" href="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/css/blueimp-gallery.min.css">
<!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->
<link rel="stylesheet" href="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/css/jquery.fileupload.css">
<link rel="stylesheet" href="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/css/jquery.fileupload-ui.css">
<!-- The Templates plugin is included to render the upload/download listings -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/tmpl.min.js"></script>
<!-- The Load Image plugin is included for the preview images and image resizing functionality -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/load-image.min.js"></script>
<!-- The Canvas to Blob plugin is included for image resizing functionality -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/canvas-to-blob.min.js"></script>
<!-- blueimp Gallery script -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/jquery.blueimp-gallery.min.js"></script>
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/jquery.iframe-transport.js"></script>
<!-- The basic File Upload plugin -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/jquery.fileupload.js"></script>
<!-- The File Upload processing plugin -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/jquery.fileupload-process.js"></script>
<!-- The File Upload image preview & resize plugin -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/jquery.fileupload-image.js"></script>
<!-- The File Upload audio preview plugin -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/jquery.fileupload-audio.js"></script>
<!-- The File Upload video preview plugin -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/jquery.fileupload-video.js"></script>
<!-- The File Upload validation plugin -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/jquery.fileupload-validate.js"></script>
<!-- The File Upload user interface plugin -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/jquery.fileupload-ui.js"></script>
<!-- The File Upload jQuery UI plugin -->
<script src="<?php echo PUBLIC_RESOURCE?>/skins/admin/js/jQuery-File-Upload/js/jquery.fileupload-jquery-ui.js"></script>

<div id='upload-product-image'>
	
	<!-- Danh sach cac hinh da upload -->		
	<div id='list-image-has-upload' class='block'>
		<h3 class='title'>Hình hảnh của sản phẩm </h3>
		<div class='content clearfix' >
			
		
		</div>
	</div>
	<!-- End danh sach cac hinh da up -->
	
	<div id='from-upload' class='block'>
		<h3 class='title'>
			Thêm hình ảnh cho sản phẩm
		</h3>
		<div class='content clearfix'>
		<!-- The file upload form used as target for the file upload widget -->
		<form id="fileupload" action="" method="POST" enctype="multipart/form-data">		    
		    <!-- The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload -->
		    <input type='hidden' name='id' value='<?php echo $this->id?>' />
		    <div class="fileupload-buttonbar">
		        <div class="fileupload-buttons">
		            <!-- The fileinput-button span is used to style the file input field as button -->
		            <span class="fileinput-button">
		                <span>Add files...</span>
		                <input type="file" name="files[]" multiple>
		            </span>
		            <button type="submit" class="start">Start upload</button>
		            <button type="reset" class="cancel">Cancel upload</button>
		           
		            <!-- The global file processing state -->
		            <span class="fileupload-process"></span>
		        </div>
		        <!-- The global progress state -->
		        <div class="fileupload-progress fade" style="display:none">
		            <!-- The global progress bar -->
		            <div class="progress" role="progressbar" aria-valuemin="0" aria-valuemax="100"></div>
		            <!-- The extended global progress state -->
		            <div class="progress-extended">&nbsp;</div>
		        </div>
		    </div>
		    <!-- The table listing the files available for upload/download -->
		    <table role="presentation"><tbody class="files"></tbody></table>
		</form>
		
		<!-- The blueimp Gallery widget -->
		<div id="blueimp-gallery" class="blueimp-gallery blueimp-gallery-controls" data-filter=":even">
		    <div class="slides"></div>
		    <h3 class="title"></h3>
		    <a class="prev">‹</a>
		    <a class="next">›</a>
		    <a class="close">×</a>
		    <a class="play-pause"></a>
		    <ol class="indicator"></ol>
		</div>
		</div>
		<!-- End content-->
	</div> 
	
</div>


<!-- The template to display files available for upload -->
<!-- The template to display files available for upload -->
<script id="template-upload" type="text/x-tmpl">
{% for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-upload fade">
        <td>
            <span class="preview"></span>
        </td>
        <td>
            <p class="name">{%=file.name%}</p>
            <strong class="error"></strong>
        </td>
        <td>
            <p class="size">Processing...</p>
            <div class="progress"></div>
        </td>
        <td>
            {% if (!i && !o.options.autoUpload) { %}
                <button class="start" disabled>Start</button>
            {% } %}
            {% if (!i) { %}
                <button class="cancel">Cancel</button>
            {% } %}
        </td>
    </tr>
{% } %}
</script>


<!-- The template to display files available for download -->
<script id="template-download" type="text/x-tmpl">

{% 
	/*
	for (var i=0, file; file=o.files[i]; i++) { %}
    <tr class="template-download fade">
        <td>
            <span class="preview">
                {% if (file.thumbnailUrl) { %}
                    <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" data-gallery><img src="{%=file.thumbnailUrl%}"></a>
                {% } %}
            </span>
        </td>
        <td>
            <p class="name">
                <a href="{%=file.url%}" title="{%=file.name%}" download="{%=file.name%}" {%=file.thumbnailUrl?'data-gallery':''%}>{%=file.name%}</a>
            </p>
            {% if (file.error) { %}
                <div><span class="error">Error</span> {%=file.error%}</div>
            {% } %}
        </td>
        <td>
            <span class="size">{%=o.formatFileSize(file.size)%}</span>
        </td>

    </tr>
{% } 
*/
%}

</script>


<script>

//hàm load image
function loadImage(){
	var link = '<?php echo $this->baseUrl('/admin/product/getlistimage/id/'.$this->id)?>';
	$.ajax({
		type: 'get',
		url: link,
		success:function(data){
			$('#list-image-has-upload .content').html(data);
		}
	});
}
loadImage();





// Initialize the jQuery UI theme switcher:
$('#theme-switcher').change(function () {
    var theme = $('#theme');
    theme.prop(
        'href',
        theme.prop('href').replace(
            /[\w\-]+\/jquery-ui.css/,
            $(this).val() + '/jquery-ui.css'
        )
    );
});

//thay cho file main.js
$(function () {
    'use strict';

    // Initialize the jQuery File Upload widget:
    $('#fileupload').fileupload({
        // Uncomment the following to send cross-domain cookies:
        //xhrFields: {withCredentials: true},
      	 url: "/admin/product/uploadtmp"
    	

    });

    // Enable iframe cross-domain access via redirect option:
    $('#fileupload').fileupload(
        'option',
        'redirect',
        window.location.href.replace(
            /\/[^\/]*$/,
            '/cors/result.html?%s'
        )
    );

    //load lại hình ảnh khi submit xong
    $('#fileupload').bind('fileuploadfinished', function (e, data){
    	loadImage();
    });



});
</script>
